package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper  extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{sid},#{gid})")
    void addSetmealAndCheckGroupInfo(@Param("sid") int sid, @Param("gid") Integer gid);

    @Select("select  id,name,age,sex,img,remark  from  t_setmeal where id = #{id}")
    SetmealVO findSetMealById(@Param("id") int id);

    @Select("SELECT  tcg.id,tcg.name,tcg.remark " +
            "FROM  t_checkgroup tcg ,t_setmeal_checkgroup tsc " +
            "where tcg.id = tsc.CHECKGROUP_ID " +
            "and  tsc.SETMEAL_ID =#{id}")
    List<CheckGroupVO> findCheckGroupsBySetmealId(@Param("id") int id);

    @Select("select CHECKGROUP_ID from t_setmeal_checkgroup where SETMEAL_ID = #{id}")
    Integer[] findCheckGroupIdsByCheckMealId(Integer id);

    @Delete("delete  from  t_setmeal_checkgroup where SETMEAL_ID =#{mealId} ")
    void deleteCheckMealAndCheckGroupByMealId(@Param("mealId") Integer mealId);

    @Insert("insert into t_setmeal_checkgroup values(#{mealId},#{itemId})")
    void addCheckMeal_CheckGroup(@Param("mealId") Integer mealId, @Param("itemId") Integer itemId);

    @Select("select * from t_setmeal")
    List<Setmeal> findAll();
}
